<?php

namespace Admin\Model;

use ArrayObject;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Sql;
use Zend\Db\TableGateway\TableGateway;

class AdminTable
{
    protected $tableGateway;
    protected $adapter;

    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
        $this->adapter = $tableGateway->getAdapter();
    }

    /**
     * 获取当前登录的管理员信息
     * @return array|ArrayObject
     */
    public function getLoginAdmin()
    {
//        $adapter = $this->adapter;
//        $sql = new Sql($adapter);
//        $select = new Select();
//        $select->from('pc_admin')
//            ->order('login_time desc');
//        $statement = $sql->prepareStatementForSqlObject($select);
//        $resultSet = $statement->execute();
        $select = $this->tableGateway->getSql()->select()->order('login_time desc');
        $resultSet = $this->tableGateway->selectWith($select);
        return $resultSet->current();
    }
}